package com.example.opengldemo.simpleGame.catcherFun;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Window;
import android.view.WindowManager;

import com.example.opengldemo.simpleGame.constant.Constant;
import com.example.opengldemo.simpleGame.util.manager.SoundManager;
import com.example.opengldemo.simpleGame.util.screenscale.ScreenScaleUtil;

import static com.example.opengldemo.simpleGame.constant.SourceConstant.moneycount;

public class MainActivity extends Activity {
	private MySurfaceView mGLSurfaceView;
	public static SoundManager sound;
	public static SharedPreferences.Editor editor;
	public static SharedPreferences sp;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		sp=this.getSharedPreferences("bn", Context.MODE_PRIVATE);    
        editor=sp.edit();
        String firstStr=sp.getString("count",null);
        System.out.println("firstStr::"+firstStr);
        if(firstStr==null)
        {
        	editor.putString("count", Integer.toString(20)); // 总数初始金币
             editor.commit();
        }
        moneycount = Integer.parseInt(sp.getString("count",null));

		
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
        		WindowManager.LayoutParams.FLAG_FULLSCREEN);
        DisplayMetrics dm=new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(dm);
        Constant.ssr= ScreenScaleUtil.calScale(dm.widthPixels, dm.heightPixels);
        
        sound=new SoundManager(this);
        mGLSurfaceView = new MySurfaceView(this);
        mGLSurfaceView.requestFocus();
        mGLSurfaceView.setFocusableInTouchMode(true);
        
        setContentView(mGLSurfaceView);

      
	}

	 @Override
    protected void onResume() {
        super.onResume();
        if(MainActivity.sound.mp!=null)
   		{
        	MainActivity.sound.mp.start();
   		}
    }

    @Override
    protected void onPause() {
        super.onPause();
        if(MainActivity.sound.mp!=null)
   		{
        	MainActivity.sound.mp.pause();
   		}
    }   
}
